package com.sgb.kjwl.viewmodel.enterprise;

import android.widget.Toast;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.view.ui.activity.enterprise.IntellpropDetailActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class IntellPropDetailModel extends BaseViewModel {
    private IntellpropDetailActivity activity;

    public IntellPropDetailModel(IntellpropDetailActivity intellpropDetailActivity) {
        this.activity = intellpropDetailActivity;
    }


    public void userFocusCompany(String shopId) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getGoodsAPI().userFocusCompany(shopId).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null)
                    return;
                if (response.body().getState().equals("ok")) {
                    activity.setUserFocusCompanyStatus();
                } else {
                    Toast.makeText(activity, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }
}
